package com.ruoyi.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goods.domain.Producer;
import com.ruoyi.goods.service.IProducerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产厂商管理Controller
 * 
 * @author zxr
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/goods/producer")
public class ProducerController extends BaseController
{
    @Autowired
    private IProducerService producerService;

    /**
     * 查询生产厂商管理列表
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Producer producer)
    {
        startPage();
        List<Producer> list = producerService.selectProducerList(producer);
        return getDataTable(list);
    }

    /**
     * 导出生产厂商管理列表
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:export')")
    @Log(title = "生产厂商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Producer producer)
    {
        List<Producer> list = producerService.selectProducerList(producer);
        ExcelUtil<Producer> util = new ExcelUtil<Producer>(Producer.class);
        util.exportExcel(response, list, "生产厂商管理数据");
    }

    /**
     * 获取生产厂商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:query')")
    @GetMapping(value = "/{producerId}")
    public AjaxResult getInfo(@PathVariable("producerId") Integer producerId)
    {
        return success(producerService.selectProducerByProducerId(producerId));
    }

    /**
     * 新增生产厂商管理
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:add')")
    @Log(title = "生产厂商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Producer producer)
    {
        return toAjax(producerService.insertProducer(producer));
    }

    /**
     * 修改生产厂商管理
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:edit')")
    @Log(title = "生产厂商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Producer producer)
    {
        return toAjax(producerService.updateProducer(producer));
    }

    /**
     * 删除生产厂商管理
     */
    @PreAuthorize("@ss.hasPermi('goods:producer:remove')")
    @Log(title = "生产厂商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{producerIds}")
    public AjaxResult remove(@PathVariable Integer[] producerIds)
    {
        return toAjax(producerService.deleteProducerByProducerIds(producerIds));
    }
}
